home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 295_01 / blkio.h < prev    next >
Text File  |  1989-12-28  |  6KB  |  179 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "blkio.h    1.2 - 89/10/31" */
  5.  
  6. /*man---------------------------------------------------------------------------
  7. NAME
  8.      blkio - block buffered input/output library
  9.  
  10. SYNOPSIS
  11.      #include <blkio.h>
  12.  
  13. DESCRIPTION
  14.      blkio is a buffered input/output library for structured files.
  15.      Because structured files are primarily accessed randomly rather
  16.      than sequentially, they are better modeled as collections of
  17.      blocks rather than as streams of characters.  This library may be
  18.      used with files which fit the following criteria:
  19.  
  20.           o A header of arbitrary (possibly zero) but fixed
  21.             length appears at the beginning of the file.
  22.           o The data following the header is arranged in
  23.             blocks of uniform size.
  24.  
  25.      Files fitting this model are referred to in the documentation as
  26.      block files.
  27.  
  28.      A file to be accessed with the blkio library is declared to be a
  29.      pointer to a defined type BLKFILE.  The bopen function creates
  30.      certain descriptive data for the file and returns a pointer to
  31.      designate it in all further transactions.
  32.  
  33. SEE ALSO
  34.      bclose, bexit, bflpop, bflpush, bflush, bgetb, bgetbf, bgeth,
  35.      bgethf, bopen, bputb, bputbf, bputh, bputhf, bsetbuf, bsetvbuf,
  36.      bsync, lockb.
  37.  
  38. ------------------------------------------------------------------------------*/
  39. #ifndef BLKIO_H        /* prevent multiple includes */
  40. #define BLKIO_H
  41.  
  42. #if __STDC__ == 1
  43. #include <stddef.h>
  44. #include <stdio.h>
  45. #define CONST    const
  46. #define SIGNED    signed
  47. #define LDOUBLE    long double
  48. #else
  49. #include <stdio.h>
  50. #include <sys/types.h>    /* replace with header containing size_t typedef */
  51. #define CONST
  52. #define SIGNED
  53. #define LDOUBLE    double
  54. #ifndef FOPEN_MAX    /* these will be in ansi stdio.h */
  55. #define FOPEN_MAX    60
  56. #endif
  57. #ifndef FILENAME_MAX
  58. #define FILENAME_MAX    25
  59. #endif
  60. #ifndef offsetof    /* these will be in ansi stddef.h */
  61. #define offsetof(struct_t, member)    ((size_t)(char *)&((struct_t *)0)->member)
  62. #endif
  63. void *calloc();        /* these will be in ansi stdlib.h */
  64. void  exit();
  65. void  free();
  66. void *malloc();
  67. void *realloc();
  68. int   memcmp();        /* these will be in ansi string.h */
  69. void *memcpy();
  70. void *memmove();
  71. void *memset();
  72. char *strcat();
  73. char *strncat();
  74. int   strcmp();
  75. char *strcpy();
  76. int   strlen();
  77. int   strncmp();
  78. char *strncpy();
  79. char *strstr();
  80. #endif    /* #if __STDC__ != 1 */
  81.  
  82. /* constants */
  83. #define BOPEN_MAX    FOPEN_MAX    /* max # block files open at once */
  84.  
  85. /* type definitions */
  86. typedef unsigned long    bpos_t;    /* block file position */
  87.  
  88. typedef union {            /* file desciptor type */
  89.     char cfd;        /* character file descriptor */
  90.     short sfd;        /* short int file descriptor */
  91.     int ifd;        /* int file descriptor */
  92.     long lfd;        /* long int file descriptor */
  93. } fd_t;
  94.  
  95. typedef struct {        /* block structure */
  96.     bpos_t bn;        /* block number */
  97.     int flags;        /* block status flags */
  98.     size_t more;        /* link to more recently accessed block */
  99.     size_t less;        /* link to less recently accessed block */
  100. } block_t;
  101.  
  102. typedef struct {        /* block file control structure */
  103.     fd_t fd;        /* file descriptor for buffered file */
  104.     int flags;        /* buffer status flags */
  105.     size_t hdrsize;        /* size of file header */
  106.     size_t blksize;        /* size of blocks */
  107.     size_t bufcnt;        /* number blocks to buffer (0 if unbuffered) */
  108.     bpos_t endblk;        /* first block past end of file */
  109.     size_t most;        /* most recently accessed block [1..bufcnt] */
  110.     size_t least;        /* least recently accessed block [1..bufcnt] */
  111.     block_t *block_p;    /* doubly linked list of blocks */
  112.     void *blkbuf;        /* buffer storage for header and blocks */
  113. } BLKFILE;
  114.  
  115. /* function declarations */
  116. #if __STDC__ == 1
  117. int        bclose(BLKFILE *bp);
  118. void        bexit(int status);
  119. int        bflpop(BLKFILE *bp, bpos_t *bn_p);
  120. int        bflpush(BLKFILE *bp, const bpos_t *bn_p);
  121. int        bflush(BLKFILE *bp);
  122. int        bgetb(BLKFILE *bp, bpos_t bn, void *buf);
  123. int        bgetbf(BLKFILE *bp, bpos_t bn, size_t offset,
  124.             void *buf, size_t bufsize);
  125. int        bgeth(BLKFILE *bp, void *buf);
  126. int        bgethf(BLKFILE *bp, size_t offset, void *buf, size_t bufsize);
  127. BLKFILE *    bopen(const char *filename, const char *type,
  128.             size_t hdrsize, size_t blksize, size_t bufcnt);
  129. int        bputb(BLKFILE *bp, bpos_t bn, const void *buf);
  130. int        bputbf(BLKFILE *bp, bpos_t bn,
  131.             size_t offset, const void *buf, size_t bufsize);
  132. int        bputh(BLKFILE *bp, const void *buf);
  133. int        bputhf(BLKFILE *bp, size_t offset,
  134.             const void *buf, size_t bufsize);
  135. int        bsetbuf(BLKFILE *bp, void *buf);
  136. int        bsetvbuf(BLKFILE *bp, void *buf, size_t blksize, size_t bufcnt);
  137. int        bsync(BLKFILE *bp);
  138. int        lockb(BLKFILE *bp, int ltype, bpos_t start, bpos_t len);
  139. #else
  140. int        bclose();
  141. void        bexit();
  142. int        bflpop();
  143. int        bflpush();
  144. int        bflush();
  145. int        bgetb();
  146. int        bgetbf();
  147. int        bgeth();
  148. int        bgethf();
  149. BLKFILE *    bopen();
  150. int        bputb();
  151. int        bputbf();
  152. int        bputh();
  153. int        bputhf();
  154. int        bsetbuf();
  155. int        bsetvbuf();
  156. int        bsync();
  157. int        lockb();
  158. #endif    /* #if __STDC__ == 1 */
  159.  
  160. /* lock types */
  161. #define B_UNLCK        (0)    /* unlock */
  162. #define B_RDLCK        (1)    /* read lock */
  163. #define B_WRLCK        (2)    /* write lock */
  164. #define B_RDLKW        (3)    /* read lock, wait */
  165. #define B_WRLKW        (4)    /* write lock, wait */
  166.  
  167. /* error codes */
  168. #define BEOS        (0)        /* start of blkio error code domain */
  169. #define BEMFILE        (BEOS - 1)    /* too many block files open */
  170. #define BENOPEN        (BEOS - 2)    /* block file is not open */
  171. #define BENBUF        (BEOS - 3)    /* buffering is off */
  172. #define BEBUF        (BEOS - 4)    /* buffering is on */
  173. #define BEBOUND        (BEOS - 5)    /* block boundary error */
  174. #define BEEOF        (BEOS - 6)    /* past end of file */
  175. #define BENFL        (BEOS - 7)    /* no free list */
  176. #define BEPANIC        (BEOS - 8)    /* internal blkio error */
  177.  
  178. #endif    /* #ifndef BLKIO_H */
  179.